<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/14
 * Time: 10:16
 */

require '../tools/DbTools.php';

$oldmoney = $_POST['oldmoney'];
$addmoney = $_POST['addmoney'];
$newmoney = $oldmoney-$addmoney;

session_start();
$usreInfo = $_SESSION[$_COOKIE['Token']];
$CardId = $usreInfo['CardId'];

if($newmoney >0){
    DbTools::InitDb();
    $sql = "INSERT INTO cardexchange(CardId,MoneyInBank,MoneyOutBank,ExchangeTime) VALUES($CardId,0,$addmoney,NOW())";
    $resutl = DbTools::noSelect($sql);
    $sql1 = "UPDATE bankcard set CardMoney = $newmoney  WHERE CardId = $CardId";
    $resutl1 = DbTools::noSelect($sql1);
    if($resutl['status'] && $resutl1['status']){
        echo '取钱成功';
        echo '<br />';
        echo '<a href="../user/userInfo.php">返回</a>';
    }else{
        echo '取钱失败： '.$resutl['message'].$resutl1['status'];
    }
}else{
    echo '账号余额不足';
    echo '<br />';
    echo '<a href="../user/userInfo.php">返回</a>';
}




